/*=========================================================================
The Impact of Denying a Wanted Abortion on Women and Children
Authors: Juliana Londoño-Vélez and Estefanía Saravia

Creation date: January 9th, 2024
--------------------------------------------------------------------------
Figure 2 - Robustness Using Judge Stringency
=========================================================================*/


* Panel A: Immediate Childbearing and Mortality

use "$data/Final_EEVV.dta", replace

global outcomes Parir_9meses Defuncion_Mama9meses Aborto_Related External Other Defuncion_Materna_DANE

mat 	a = J(6,5,.)

matrix rownames a =  $outcomes 

local c=1
foreach var in  $outcomes {

sum `var' if Niega==0
mat 	a[`c',1] = r(mean)

ivreghdfe `var'         (Niega=Mujer_Ponente)  , abs(oficina#time) cluster(id_juez) savefirst

mat 	a[`c',2]  = _b[Niega]
mat 	a[`c',3] = _se[Niega]



ivreghdfe `var'         (Niega=judge_stringency), abs(oficina#time) cluster(id_juez) savefirst

mat 	a[`c',4]  = _b[Niega]
mat 	a[`c',5] = _se[Niega]


local c=`c'+1
}

	svmat2 a, rnames(outcome)
	
	drop if outcome==""
	
	rename a1 mean_nondenied_stringency
	rename a2 coef_women
	rename a3 se_women
	rename a4 coef_stringency
	rename a5 se_stringency
	
	
	keep outcome coef_women se_women coef_stringency se_stringency
	
	sort outcome
	
	gen l_CI_women  =  coef_women - (se_women)*1.96
	gen u_CI_women  =  coef_women + (se_women)*1.96
	
	gen l_CI_stringency  =  coef_stringency - (se_stringency)*1.96
	gen u_CI_stringency  =  coef_stringency + (se_stringency)*1.96

	reshape long coef_ se_ l_CI_ u_CI_, i(outcome) string
		
	gen i=1 if outcome=="Parir_9meses" & _j=="stringency"
	replace i=2 if outcome=="Parir_9meses" & _j=="women"
	replace i=4 if outcome=="Defuncion_Mama9meses" & _j=="stringency"
	replace i=5 if outcome=="Defuncion_Mama9meses" & _j=="women"
	replace i=7 if outcome=="Aborto_Related" & _j=="stringency"
	replace i=8 if outcome=="Aborto_Related" & _j=="women"
	replace i=10 if outcome=="Defuncion_Materna_DANE" & _j=="stringency"
	replace i=11 if outcome=="Defuncion_Materna_DANE" & _j=="women"
	replace i=13 if outcome=="Other" & _j=="stringency"
	replace i=14 if outcome=="Other" & _j=="women"
	replace i=16 if outcome=="External" & _j=="stringency"
	replace i=17 if outcome=="External" & _j=="women"

	
	sort i
	gen mas = (_j=="stringency")

	
sort i
	
	twoway (rcapsym  u_CI_ l_CI_ i if mas==0, msymbol(|) lcolor(black) mcolor(black)  horizontal) (scatter i coef_ if mas==0,   mcolor(black) msize(0.8) msymbol(circle)) (rcapsym  u_CI_ l_CI_ i if mas==1, msymbol(|) lcolor(blue) mcolor(blue)  horizontal) (scatter i coef_  if mas==1,   mcolor(blue) msize(0.8) msymbol(triangle)), xtitle("IV Coefficient and 95% CI", size(small)) ytitle("") ylabel(1.5(2)30.5) xlab(,nogrid) ylab(1.5 "Live birth" 4.5 "Death" 7.5 "Septicemia and infections" 10.5 "Obstetric causes" 13.5 "Other health causes" 16.5 "External causes",nogrid labsize(small)) xline(0, lpattern(dash) lcolor(gray) lwidth(thin)) yscale(reverse) xlabel(,labsize(small)) legend(order(4 "Judge stringency" 2 "Female judge" ) pos(4) ring(0) region(lcolor(none) lwidth(none)) size(small) rows(2))
	

		graph export "$output/Figure2_PanelA.pdf", replace

		
* Panel B: Long-Term Outcomes forWomen



use "$data/Final_Medellin_SisbenIV.dta", replace

global outcomes Media  Soltera Casada Divorciada_Viuda Numero_Hijos Familias_Accion Enfermo_30 Grupo_AB Ocupado


mat 	a = J(9,5,.)

matrix rownames a =  $outcomes 

local c=1
foreach var in  $outcomes {

sum `var' if Niega==0
mat 	a[`c',1] = r(mean)

ivreghdfe `var'         (Niega=Mujer_Ponente)  , abs(oficina#time) cluster(id_juez) savefirst

mat 	a[`c',2]  = _b[Niega]
mat 	a[`c',3] = _se[Niega]



ivreghdfe `var'         (Niega=judge_stringency), abs(oficina#time) cluster(id_juez) savefirst

mat 	a[`c',4]  = _b[Niega]
mat 	a[`c',5] = _se[Niega]


local c=`c'+1
}

	svmat2 a, rnames(outcome)
	
	drop if outcome==""
	
	rename a1 mean_nondenied_stringency
	rename a2 coef_women
	rename a3 se_women
	rename a4 coef_stringency
	rename a5 se_stringency
	
	
	keep outcome coef_women se_women coef_stringency se_stringency
	
	sort outcome
	
	gen l_CI_women  =  coef_women - (se_women)*1.96
	gen u_CI_women  =  coef_women + (se_women)*1.96
	
	gen l_CI_stringency  =  coef_stringency - (se_stringency)*1.96
	gen u_CI_stringency  =  coef_stringency + (se_stringency)*1.96

	reshape long coef_ se_ l_CI_ u_CI_, i(outcome) string
		
	gen i=1 if outcome=="Numero_Hijos" & _j=="stringency"
	replace i=2 if outcome=="Numero_Hijos" & _j=="women"
	replace i=4 if outcome=="Soltera" & _j=="stringency"
	replace i=5 if outcome=="Soltera" & _j=="women"
	replace i=7 if outcome=="Casada" & _j=="stringency"
	replace i=8 if outcome=="Casada" & _j=="women"
	replace i=10 if outcome=="Divorciada_Viuda" & _j=="stringency"
	replace i=11 if outcome=="Divorciada_Viuda" & _j=="women"
	replace i=13 if outcome=="Enfermo_30" & _j=="stringency"
	replace i=14 if outcome=="Enfermo_30" & _j=="women"
	replace i=16 if outcome=="Media" & _j=="stringency"
	replace i=17 if outcome=="Media" & _j=="women"
	replace i=19 if outcome=="Ocupado" & _j=="stringency"
	replace i=20 if outcome=="Ocupado" & _j=="women"
	replace i=22 if outcome=="Grupo_AB" & _j=="stringency"
	replace i=23 if outcome=="Grupo_AB" & _j=="women"
	replace i=25 if outcome=="Familias_Accion" & _j=="stringency"
	replace i=26 if outcome=="Familias_Accion" & _j=="women"

	sort i
	gen mas = (_j=="stringency")


sort i	
	
	twoway (rcapsym  u_CI_ l_CI_ i if mas==0, msymbol(|) lcolor(black) mcolor(black)  horizontal) (scatter i coef_ if mas==0,   mcolor(black) msize(0.8) msymbol(circle)) (rcapsym  u_CI_ l_CI_ i if mas==1, msymbol(|) lcolor(blue) mcolor(blue)  horizontal) (scatter i coef_  if mas==1,   mcolor(blue) msize(0.8) msymbol(triangle)), xtitle("IV Coefficient and 95% CI", size(small)) ytitle("") ylabel(1.5(2)30.5) xlab(,nogrid) ylab(1.5 "Number of children" 4.5 "Never-married" 7.5 "Married or cohabitating" 10.5 "Divorced or separated" 13.5 "Had a health problem (last 30 days)" 16.5 "High school diploma" 19.5 "Employed or looking for job" 22.5 "Extreme or moderate poverty" 25.5 "Familias en Acción recipient",nogrid labsize(small)) xline(0, lpattern(dash) lcolor(gray) lwidth(thin)) yscale(reverse) xlabel(,labsize(small)) legend(order(4 "Judge stringency" 2 "Female judge") pos(4) ring(0) region(lcolor(none) lwidth(none)) size(small) rows(2))
	
			graph export "$output/Figure2_PanelB.pdf", replace

			
* Panel C : Long-Term Outcomes for Children
			
use "$data/Final_Medellin_Children.dta", replace

	
keep if ultimo_hijo==1
	
global outcomes Estudia Inasistencia_Escolar Rezago_Escolar Trabajo_Infantil Cuidado_1 Cuidado_2 Cuidado_5 Cuidado_6 Cuidado_7  


mat 	a = J(9,5,.)

matrix rownames a =  $outcomes 

local c=1
foreach var in  $outcomes {

sum `var' if Niega==0
mat 	a[`c',1] = r(mean)

ivreghdfe `var'         (Niega=Mujer_Ponente)  , abs(oficina#time) cluster(id_juez) savefirst

mat 	a[`c',2]  = _b[Niega]
mat 	a[`c',3] = _se[Niega]



ivreghdfe `var'         (Niega=judge_stringency), abs(oficina#time) cluster(id_juez) savefirst

mat 	a[`c',4]  = _b[Niega]
mat 	a[`c',5] = _se[Niega]


local c=`c'+1
}

	svmat2 a, rnames(outcome)
	
	drop if outcome==""
	
	rename a1 mean_nondenied_stringency
	rename a2 coef_women
	rename a3 se_women
	rename a4 coef_stringency
	rename a5 se_stringency
	
	
	keep outcome coef_women se_women coef_stringency se_stringency
	
	sort outcome
	
	gen l_CI_women  =  coef_women - (se_women)*1.96
	gen u_CI_women  =  coef_women + (se_women)*1.96
	
	gen l_CI_stringency  =  coef_stringency - (se_stringency)*1.96
	gen u_CI_stringency  =  coef_stringency + (se_stringency)*1.96

	reshape long coef_ se_ l_CI_ u_CI_, i(outcome) string
		
	gen i=1 if outcome=="Estudia" & _j=="stringency"
	replace i=2 if outcome=="Estudia" & _j=="women"
	replace i=4 if outcome=="Inasistencia_Escolar" & _j=="stringency"
	replace i=5 if outcome=="Inasistencia_Escolar" & _j=="women"
	replace i=7 if outcome=="Rezago_Escolar" & _j=="stringency"
	replace i=8 if outcome=="Rezago_Escolar" & _j=="women"
	replace i=10 if outcome=="Trabajo_Infantil" & _j=="stringency"
	replace i=11 if outcome=="Trabajo_Infantil" & _j=="women"
	replace i=13 if outcome=="Cuidado_1" & _j=="stringency"
	replace i=14 if outcome=="Cuidado_1" & _j=="women"
	replace i=16 if outcome=="Cuidado_2" & _j=="stringency"
	replace i=17 if outcome=="Cuidado_2" & _j=="women"
	replace i=19 if outcome=="Cuidado_5" & _j=="stringency"
	replace i=20 if outcome=="Cuidado_5" & _j=="women"
	replace i=22 if outcome=="Cuidado_6" & _j=="stringency"
	replace i=23 if outcome=="Cuidado_6" & _j=="women"
	replace i=25 if outcome=="Cuidado_7" & _j=="stringency"
	replace i=26 if outcome=="Cuidado_7" & _j=="women"

	sort i
	gen mas = (_j=="stringency")


sort i	
	
	twoway (rcapsym  u_CI_ l_CI_ i if mas==0, msymbol(|) lcolor(black) mcolor(black)  horizontal) (scatter i coef_ if mas==0,   mcolor(black) msize(0.8) msymbol(circle)) (rcapsym  u_CI_ l_CI_ i if mas==1, msymbol(|) lcolor(blue) mcolor(blue)  horizontal) (scatter i coef_  if mas==1,   mcolor(blue) msize(0.8) msymbol(triangle)), xtitle("IV Coefficient and 95% CI", size(small)) ytitle("") ylabel(1.5(2)30.5) xlab(,nogrid) ylab(1.5 "Attends preschool, school, or college" 4.5 "Truancy" 7.5 "Grade retention" 10.5 "Working" 13.5 "Daycare or school" 16.5 "Home with parent" 19.5 "Home with an adult relative" 22.5 "Home with child relative" 25.5 "Home alone",nogrid labsize(small)) xline(0, lpattern(dash) lcolor(gray) lwidth(thin)) yscale(reverse) xlabel(,labsize(small)) legend(order(4 "Judge stringency" 2 "Female judge") pos(2) ring(0) region(lcolor(none) lwidth(none)) size(small) rows(2))

			graph export "$output/Figure2_PanelC.pdf", replace
